//
//  BaseViewController.m
//  TeacherNet
//
//  Created by slz on 2017/11/1.
//  Copyright © 2017年 bnsr. All rights reserved.
//

#import "BaseViewController.h"

@interface TTBaseViewController ()
@property (nonatomic, assign) BOOL gk_statusBarStyle;

@end



@implementation TTBaseViewController


- (CGFloat)customNavigationHeight
{
    
    return kNavigationBarHeight;
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil
                         bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        UIImage* img = [UIImage imageNamed:@"white_logo"];
        self.navigationItem.titleView = [[UIImageView alloc] initWithImage:img];
        self.showNavigationBar = NO;
        self.popGestureRecognizerEnable = YES;
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}
//
//- (void)viewDidLayoutSubviews {
//    [super viewDidLayoutSubviews];
//    UIEdgeInsets safeAreaInsets = sgm_safeAreaInset(self.view);
//    CGFloat height = 44.0; // 导航栏原本的高度，通常是44.0
//    height += safeAreaInsets.top > 0 ? safeAreaInsets.top : 20.0; // 20.0是statusbar的高度，这里假设statusbar不消失
//    if (_navigationbar && _navigationbar.height != height) {
//        _navigationbar.height = height;
//    }
//}


#pragma mark - 屏幕旋转
- (BOOL)shouldAutorotate
{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (self.pageName.length == 0 || !self.pageName){
        self.pageName = NSStringFromClass([self class]);
    }
    
    
    [self.navigationController setNavigationBarHidden:!self.showNavigationBar animated:animated];
    UIColor *color = [UIColor whiteColor];
    UIImage *image = [UIImage imageWithColor:color];
    [self.navigationController.navigationBar setBackgroundImage:image
                                                 forBarPosition:UIBarPositionTopAttached
                                                     barMetrics:UIBarMetricsDefault];
    
    for (UIGestureRecognizer * pan in self.navigationController.view.gestureRecognizers) {
        if ([pan isKindOfClass:[UIPanGestureRecognizer class]]){
            pan.enabled = _popGestureRecognizerEnable;
        }
    }
    [self setNeedsStatusBarAppearanceUpdate];
}
//set status bar white color
- (void)viewDidLoad{
    [super viewDidLoad];
    
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    
    
    //    id target = self.
    //    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(HandleNavigationTransition:)];
    
    
    //    @weakify(self);
    //    self.navigationController.interactivePopGestureRecognizer.delegate = weak_self;
    //    if (self.navigationController && [self.navigationController.viewControllers count] == 1) {
    //        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    //    }else{
    //        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    //    }
}


- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDefault;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    if (!self.pageName || self.pageName.length == 0){
        self.pageName = NSStringFromClass([self class]);
    }
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


@implementation TTRootBaseViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil
                         bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.automaticallyAdjustsScrollViewInsets = NO;
        self.edgesForExtendedLayout = UIRectEdgeTop;
        self.hidesBottomBarWhenPushed = NO;
        self.showNavigationBar = YES;
    }
    return self;
}
    
    
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}



@end
